// Detail 模块仓库 vuex~
import {requestGoodsInfo} from "@/api/index.js";
import {reqAddOrUpdateShopCart} from "@/api/index.js";

import {getUUID} from "@/utils/uuid_token.js";

const actions = {
  async gotGoodInfo({commit}, skuId) {
    let xml = await requestGoodsInfo(skuId);
    if(xml.data.code === 200) {
      commit("GOTGOODINFO", xml.data.data);
    }
  },

  async addOrUpdateShopCart({commit}, {skuId, skuNum}) {
    let xml = await reqAddOrUpdateShopCart(skuId, skuNum);
    return xml;
  },
  
};

const mutations = {  
  GOTGOODINFO(state, value) {
    state.gotInfo = value;    
  }
};

const state = {
  gotInfo: null,
  uuid_token: getUUID(),
};

const getters = {
  categoryView(state) {
    if(state.gotInfo) {        
      return state.gotInfo.categoryView;
    }else { return []; }        
  },
  skuInfo(state) {             
    return state.gotInfo ? state.gotInfo.skuInfo : false;
  },
  spuSaleAttrList(state) {  
    
    return state.gotInfo ? state.gotInfo.spuSaleAttrList : [];
  }
};

export default {
  actions,
  mutations,
  state,
  getters,
}
 